
    function init_google_map_auto_search() {
      var input = document.getElementById('theAddress');
      var autocomplete = new google.maps.places.Autocomplete(input);
      autocomplete.setComponentRestrictions({ 'country': 'au' });
    }

    function document_load(){
      zoyoe.map = new MapInfoCore(function(){},null,null,null);
      if(zoyoe.ElementExtension){
        zoyoe.ElementExtension.BuildExtensionElements();
      }

      init_google_map_auto_search();

      var cityName = '{{CityName}}';

      YUI().use("node",'event','io',function(Y){

         var filter = getParam('filter');
         
         if(filter == undefined || filter == null || filter == ''){
             // alert("setting filter");
             if(window.location.pathname=='/sydney_brothel_escort_massage_list/'){
              filter='{"LOCATION":{"x":-33.86899948120117,"y":151.2091827392578},"TARGET":"general","MAIN":"","STYPE":"All","LOCAL":"","NATION":"Australia,China,Hong Kong,India,Japan,Korea,Lebanon,Macau,Malaysia,Mongolia,Russian,Singapore,South Africa,Taiwan,Thailand,Turkey,Viet Nam","RADIUS":3000,"PRICE":{"MIN":0,"MAX":900},"AGE":"","OAD":"Sydney CBD, New South Wales"}';
             }else{
             filter='{"LOCATION":{"x":-25.5849990844,"y":134.5039978027},"TARGET":"general","MAIN":"","STYPE":"All","LOCAL":"","NATION":"Australia,China,Hong Kong,India,Japan,Korea,Lebanon,Macau,Malaysia,Mongolia,Russian,Singapore,South Africa,Taiwan,Thailand,Turkey,Viet Nam","RADIUS":3000,"PRICE":{"MIN":0,"MAX":900},"AGE":"","OAD":""}';
             }
         }

         var filterObj = eval ("(" + filter + ")");

         var search_option = Y.one("#match-option");
         zoyoe.InitZoyoe(false,Y);
         zoyoe.search = InitSearch(search_option,"/general",MarkValidate,MarkInvalidate);
         zoyoe.admin = InitAdmin(zoyoe);

         if(filterObj.TARGET == 'item'){
           zoyoe.search.SetPreference('item',1);
         }else{
           zoyoe.search.SetPreference('general',0);
         }
         var searchInput = Y.one("#main-search-bar input");
         var nationalityDiv = Y.Node.getDOMNode(Y.one("#nationality input")).parentNode;
         var radiusDiv = Y.Node.getDOMNode(Y.one("#radius input")).parentNode;
         var priceDiv = Y.Node.getDOMNode(Y.one("#price input")).parentNode;
         var ageDiv = Y.Node.getDOMNode(Y.one("#age input")).parentNode;
         if (searchInput != null) {
           var tipMsg = "";
           var addressTipMsg = "Please enter your location or postcode";
           var searchInputNode = Y.Node.getDOMNode(searchInput);
           var generalTarget = Y.one("#match-option").all("a").item(0);
           var girlTarget = Y.one("#match-option").all("a").item(1);
           tipMsg = addressTipMsg;
           if(filterObj.OAD != '' && filterObj.OAD != undefined) {
            var inAddress = Y.one("#theAddress");
            var inAddressNode = Y.Node.getDOMNode(inAddress);
            inAddressNode.value = filterObj.OAD.replace(/\+/g," ");
           }else{
            searchInputNode.value = tipMsg;

            searchInputNode.style.color = "grey";
           }

           nationalityDiv.className = "extension-combo-select";
           radiusDiv.className = "extension-drop-list";
           if(filterObj.TARGET == 'item'){
               priceDiv.className = "extension-drop-list-disabled";
               ageDiv.className = "extension-drop-list";
           }else{
               priceDiv.className = "extension-drop-list";
               ageDiv.className = "extension-drop-list-disabled";
           }

           searchInput.on('focus', function(e){
             if (searchInputNode.value == tipMsg) {
               searchInputNode.value = "";
               searchInputNode.style.color = "black";
             }
           });
           searchInput.on('blur', function(e){
             if (searchInputNode.value == "") {
               searchInputNode.value = tipMsg;
               searchInputNode.style.color = "grey";
             }
           });
           generalTarget.on('click', function(e){
             tipMsg = addressTipMsg;
             if (searchInputNode.value == "") {
                 searchInputNode.value = tipMsg;
                 searchInputNode.style.color = "grey";
             }
             // update the filters
             nationalityDiv.className = "extension-combo-select";
             radiusDiv.className = "extension-drop-list";
             priceDiv.className = "extension-drop-list";
             ageDiv.className = "extension-drop-list-disabled";
           });

           girlTarget.on('click', function(e){
             tipMsg = addressTipMsg;
             if (searchInputNode.value == "") {
                 searchInputNode.value = tipMsg;
             }
             nationalityDiv.className = "extension-combo-select";
             radiusDiv.className = "extension-drop-list";
             priceDiv.className = "extension-drop-list-disabled";
             ageDiv.className = "extension-drop-list";
           });
         }

      });
    }

    function setType(type) {
      YUI().use("node",function(Y){
         var links = Y.one("#service-type").all("a");
         var typeInput = Y.one("#service-type input");
         var index = 0;
         if (type == "Brothel") {
           index = 1;
         } else if (type == "Escort") {
           index = 2;
         } else if (type == "Massage") {
           index = 3;
         } else if (type == "All") {
           index = 0;
         }
         typeInput.set('value',type);
         links.set('className','filter-button');
         links.item(index).set('className','filter-button-select');
      });
    }

/*
   {% if DATA|length == 0 and SIDEDATA|length == 0 %}
    zoyoe.maptoggle = 1;
   {% else %}
    zoyoe.maptoggle = 0;
   {% endif %}
*/
   function mapToggle(ele){
      zoyoe.maptoggle = 1 - zoyoe.maptoggle;
      YUI().use('node','anim',function(Y){
        var dense = Y.one('#sup-lane div.dense').get('offsetHeight');
        if(zoyoe.maptoggle == 1){
          var anim = new Y.Anim({
            node:'#sup-lane',
            to:{height:zoyoe.n2px(dense+20)},
            duration:0.2,
          });
          anim.run();
          ele.src = "/res/icons/arrow_up.png";
        }else{
          Y.one('#sup-lane').setStyle('height',"80px");
          ele.src = "/res/icons/arrow_down.png";
        } 
      });
    }
function pressEnter(e){
var keynum;
        if(window.event) // IE8 and earlier
                {
                keynum = e.keyCode;
                }
        else if(e.which) // IE9/Firefox/Chrome/Opera/Safari
                {
                keynum = e.which;
                }
        if (keynum == 13){
                zoyoe.search.PreSearch();
        }
}

function getParam(paramName)
{
        paramValue = "";
        isFound = false;
        if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=")>1)
        {
            arrSource = unescape(this.location.search).substring(1,this.location.search.length).split("&");
            i = 0;
            while (i < arrSource.length && !isFound)
            {
                if (arrSource[i].indexOf("=") > 0)
                {
                     if (arrSource[i].split("=")[0].toLowerCase()==paramName.toLowerCase())
                     {
                        paramValue = arrSource[i].split("=")[1];
                        isFound = true;
                     }
                }
                i++;
            }   
        }
   return paramValue;
}
